﻿using System;
using System.Windows.Controls;
using System.Windows.Threading;

namespace Oliver.Controls
{
    public class MemoryCheck : UserControl
    {
        public MemoryCheck()
        {
#if DEBUG
            _timer.Tick += _timer_Tick;
            _timer.Interval = new TimeSpan(0, 0, 5);
            _timer.Start();
#endif
        }

#if DEBUG

        long _max = 0;

        void _timer_Tick(object sender, EventArgs e)
        {
            UpdateValues();
        }

        private void UpdateValues()
        {
            long totalMemory = GC.GetTotalMemory(true) / 1024;

            if (_max < totalMemory)
            {
                _max = totalMemory;
            }

            string result = totalMemory.ToString() + "KB/" +_max.ToString() + "KB";

            TextBlock tb = new TextBlock();
            tb.Text = result;
            tb.Foreground = this.Foreground;
            this.Content = tb;
        }

        DispatcherTimer _timer = new DispatcherTimer();
    }
#endif

}
